package com.applink.sell_proof.urlimageviewhelper;

import java.util.List;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class BaseClaimPagerAdapter extends PagerAdapter {
	protected final List<Object> mResources;
	protected final Context mContext;

	protected int mCurrentPosition = -1;

	protected OnItemClaimChangeListener mOnItemChangeListener;

	public BaseClaimPagerAdapter() {
		mResources = null;
		mContext = null;
	}

	public BaseClaimPagerAdapter(Context context, List<Object> resources) {
		this.mResources = resources;
		this.mContext = context;
	}

	@Override
	public void setPrimaryItem(ViewGroup container, int position, Object object) {
		super.setPrimaryItem(container, position, object);
		if (mCurrentPosition == position)
			return;

		GalleryClaimViewPager galleryContainer = ((GalleryClaimViewPager) container);

		if (galleryContainer.mCurrentView != null)
			// galleryContainer.mCurrentView.resetScale();

			mCurrentPosition = position;
		if (mOnItemChangeListener != null)
			mOnItemChangeListener.onItemChange(mCurrentPosition);
	}

	@Override
	public void destroyItem(ViewGroup collection, int position, Object view) {
		collection.removeView((View) view);
	}

	@Override
	public int getCount() {
		return mResources.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view.equals(object);
	}

	@Override
	public void finishUpdate(ViewGroup arg0) {
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(ViewGroup arg0) {
	}

	public int getCurrentPosition() {
		return mCurrentPosition;
	}

	public void setOnItemChangeListener(OnItemClaimChangeListener listener) {
		mOnItemChangeListener = listener;
	}

	public static interface OnItemClaimChangeListener {
		public void onItemChange(int currentPosition);
	}
}
